import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import icon1 from "@/image/icon/defect.png"
import icon2 from "@/image/icon/rolling.png"
import icon3 from "@/image/icon/material-reason.png"
import icon4 from "@/image/icon/continuous-cast.png"
import icon5 from "@/image/icon/alert.png"

export default new Vuex.Store({
  state: {
    user: JSON.parse(window.localStorage.getItem('user') || 'null') // 当前登录用户状态
  },
  getters: {
    nodeIcons(){
      var icons = [icon1,icon2,icon3,icon4,icon5];
      var labels = ["缺陷","轧制阶段原因","物料原因","连铸阶段原因","报警"];
      var arr = [];
      for(var i=0;i<icons.length;i++){
        arr.push({
          icon:icons[i],
          name:labels[i]
        })
      }
      return arr;
    },
    account(state) {
      if(state.user) {
        return state.user.user.account
      }
      return ''
    }
  },
  mutations: {
    setUser (state, payload) {
      state.user = JSON.parse(payload)
      // 用户数据持久化 本地存储
      window.localStorage.setItem('user', payload)
    },
    clearUser (state) {
      state.user = null
    }
  },
  actions: {
  },
  modules: {
  }
})
